<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise操作</title>
   <script>
       function getNum(){
           let num =10
           //1.声明promise
           return new Promise(function(reslove,reject){
               let id = setInterval(function(){
                   num--
                   if(num===0){
                       clearTimeout(id)
                       //2.保存异步执行的结果num
                       reslove(num)
                   }
                   //console.log(num)
               },100)
           })
       }
       let promise = getNum()
       //3.取出promise保存的异步执行的结果
       promise.then(function(res){
           console.log(res);   
       })
   </script>
</head>
<body>
    <div id="app"> </div>
</body>
</html>